package com.hjq.fcloud.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.hjq.fcloud.R;


public class GlideUtils {


    public static void loadHead(Context mContext, ImageView imageView, String url) {

        Glide.with(mContext)
                .load(url)
                .placeholder(R.drawable.avatar_placeholder_ic)
                .error(R.drawable.avatar_placeholder_ic)
                .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop()))
                .into(imageView);

    }

    /**
     * 公共加载图片方法
     *
     * @param mContext
     * @param imageView
     * @param url
     */
    public static void loadImage(Context mContext, ImageView imageView, String url) {
        int roundingRadius = (int) mContext.getResources().getDimension(R.dimen.dp_6);

        Glide.with(mContext)
                .load(url)
                .placeholder(R.mipmap.ic_place_holder)
                .error(R.mipmap.ic_place_holder)
                .apply(new RequestOptions()
                        .transforms(new CenterCrop(), new RoundedCorners(roundingRadius)
                        ))
                .into(imageView);
    }

    public static void loadImageLocal(Context mContext, ImageView imageView, int localImgUrl) {
        int roundingRadius = (int) mContext.getResources().getDimension(R.dimen.dp_6);

        Glide.with(mContext)
                .load(localImgUrl)
                .placeholder(R.mipmap.ic_place_holder)
                .error(R.mipmap.ic_place_holder)
                .apply(new RequestOptions()
                        .transforms(new CenterCrop(), new RoundedCorners(roundingRadius)
                        ))
                .into(imageView);
    }

    public static void loadImageGifLocal(Context mContext, ImageView imageView, int localImgid) {

        Glide.with(mContext)
                .asGif()
                .load(localImgid)
                .into(imageView);
    }

    public static void loadImageResource(Context mContext, ImageView imageView, int resourceId) {
        Glide.with(mContext)
                .load(resourceId)
                .placeholder(imageView.getDrawable())
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .into(imageView);

    }

    /**
     * 公共加载图片方法
     *
     * @param mContext
     * @param imageView
     * @param url
     */
    public static void loadImageNoRadis(Context mContext, ImageView imageView, String url) {

        Glide.with(mContext)
                .load(url)
                .placeholder(R.mipmap.ic_place_holder)
                .error(R.mipmap.ic_place_holder)
                .into(imageView);
    }

    /**
     * 公共加载图片方法
     *
     * @param mContext
     * @param imageView
     * @param url
     */
    public static void loadImagefitCenter(Context mContext, ImageView imageView, String url) {

        Glide.with(mContext)
                .load(url)
                .placeholder(R.mipmap.ic_place_holder)
                .error(R.mipmap.ic_place_holder)
                .fitCenter()
                .into(imageView);
    }

}
